package com.webdev.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.webdev.domain.Personnel;
import com.webdev.service.PersonnelService;
import com.webdev.service.RequestService;
import com.webdev.service.imp.PersonnelServiceImp;
import com.webdev.service.imp.RequestServiceImp;

import net.sf.json.JSONArray;

/**
 * Servlet implementation class RequestListServlet
 */
@WebServlet("/RequestListServlet")
public class RequestListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/*
     * 根据前端传来的id和身份返回请假请求，老板有权限查看所有人的请求，员工只能查看自己的请求
     * */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String pidentity = request.getParameter("pidentity");
		if(pidentity.equals("老板")) {
			RequestService service = new RequestServiceImp();
			JSONArray ja = new JSONArray();
			ja = service.getJSONArray(service.bossSearch());
			response.setCharacterEncoding("utf-8");
			response.getWriter().write(ja.toString());
		}
		else if(pidentity.equals("员工")) {
			PersonnelService pservice = new PersonnelServiceImp();
			Personnel personnel = new Personnel();
			personnel = pservice.getPersonnelById(Integer.parseInt(request.getParameter("pid")));
			RequestService rservice = new RequestServiceImp();
			JSONArray ja = new JSONArray();
			ja = rservice.getJSONArray(rservice.staffSearch(personnel));
			response.setCharacterEncoding("utf-8");
			response.getWriter().write(ja.toString());
		}
		else {
			
		}
	}

}
